﻿<UserControl x:Class="Agnes.MyDocsLib.DocsLibSmartTreeView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
             xmlns:dxn="http://schemas.devexpress.com/winfx/2008/xaml/navbar"
             xmlns:local="clr-namespace:Agnes.MyDocsLib"
             FontSize="12"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300" >
    <UserControl.Resources>
        <local:ArticleNodeToTitleConverter x:Key="TitleConverter" />
        <local:ArticleToCollapsedConverter x:Key="ArticleCollapsedConverter" />
        <local:CatalogToCollapsedConverter x:Key="CatalogToCollaspedConvter" />
        <local:ArticleNodeToIdConverter x:Key="IdConverter"/>
    </UserControl.Resources>
    <Grid >
        <Grid.Resources>
            <HierarchicalDataTemplate x:Key="ArticleHDT" DataType="{x:Type local:IArticleNode}" ItemsSource="{Binding Path=Childs}">
                <StackPanel Margin="0.2" Orientation="Horizontal" Tag="{Binding Converter={StaticResource IdConverter} }"
                            PreviewMouseDown="StackPanel_PreviewMouseDown">
                    <StackPanel.ContextMenu>
                        <ContextMenu>
                            <MenuItem Header="新建" Visibility="{Binding Converter={StaticResource CatalogToCollaspedConvter}}">
                                <MenuItem Header="新建同级目录" Command="local:NewSameLevelCatalogCmd.Requery"/>
                                <MenuItem Header="新建子目录" Command="local:NewSubCatalogCmd.Requery"/>
                                <MenuItem Header="新建文章" Command="local:NewArticleCmd.Requery"/>
                            </MenuItem>
                            <MenuItem Header="重命名" Command="local:RenameCmd.Requery"
                                      Visibility="{Binding Converter={StaticResource CatalogToCollaspedConvter}}" />
                            <!--<MenuItem Header="删除" />-->
                            <Separator Visibility="{Binding Converter={StaticResource ArticleCollapsedConverter}}" />
                            <MenuItem Header="浏览" Visibility="{Binding Converter={StaticResource ArticleCollapsedConverter}}"
                                      Command="local:PreviewArticleCmd.Requery" />
                            <MenuItem Header="编辑" Visibility="{Binding Converter={StaticResource ArticleCollapsedConverter}}"
                                      Command="local:EditArticleCmd.Requery"/>
                        </ContextMenu>
                    </StackPanel.ContextMenu>
                    <Image/>
                    <TextBlock Text="{Binding Path=Title}" />
                </StackPanel>
            </HierarchicalDataTemplate>
        </Grid.Resources>

        <dxn:NavBarControl >
            <!--<dxn:NavBarControl.View>
                <dxn:SideBarView>

                </dxn:SideBarView>
            </dxn:NavBarControl.View>-->
            <dxn:NavBarControl.Groups>
                <dxn:NavBarGroup Header="我的知识库" >
                    <Grid>
                        <TreeView Name="tvMyDocsTree"
                                  ItemsSource="{Binding Path=DocsTree}" Background="White"
                                  ItemTemplate="{StaticResource ArticleHDT}" >
                            <TreeView.ItemContainerStyle>
                                <Style TargetType="{x:Type TreeViewItem}">
                                    <Style.Resources>
                                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="LightBlue" Opacity=".5"/>
                                        <SolidColorBrush x:Key="{x:Static SystemColors.HighlightTextBrushKey}" Color="Black" />
                                    </Style.Resources>
                                    <Style.Triggers>
                                        <Trigger Property="IsSelected" Value="true">
                                            <Setter Property="FontSize" Value="14" />
                                            <Setter Property="BorderBrush" Value="Blue" />
                                            <Setter Property="BorderThickness" Value="0.5" />
                                        </Trigger>
                                    </Style.Triggers>
                                    <EventSetter Event="TreeViewItem.PreviewMouseRightButtonDown"
                                                 Handler="TreeViewItem_PreviewMouseRightButtonDown"/>
                                    
                                </Style>
                            </TreeView.ItemContainerStyle>
                        </TreeView>
                    </Grid>
                </dxn:NavBarGroup>
                <dxn:NavBarGroup Header="我的日记本">

                </dxn:NavBarGroup>
            </dxn:NavBarControl.Groups>
        </dxn:NavBarControl>
    </Grid>
</UserControl>
    